<template>
  <div>
    <el-card class="container">
      <el-form inline class="container" :disabled="disabled">
        <el-form-item label="一级菜单">
          <!-- 自定义事件 getCategory2List()里面是默认接收的参数是直接想要 -->
          <el-select
            placeholder="请选择一级菜单"
            :value="category1Id"
            @change="getCategory2List"
          >
            <el-option
              v-for="c1 in category1List"
              :key="c1.id"
              :label="c1.name"
              :value="c1.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级菜单">
          <el-select
            placeholder="请选择二级菜单"
            :value="category2Id"
            @change="getCategory3List"
          >
            <el-option
              v-for="c2 in category2List"
              :key="c2.id"
              :label="c2.name"
              :value="c2.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三级菜单">
          <el-select
            placeholder="请选择三级菜单"
            :value="category3Id"
            @change="SET_CATEGORY_3ID"
          >
            <el-option
              v-for="c3 in category3List"
              :key="c3.id"
              :label="c3.name"
              :value="c3.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from 'vuex'
export default {
  name: 'CategorySelector',
  mounted() {
    this.getCategory1List()
  },
  props: {
    disabled: Boolean
  },
  computed: {
    ...mapState('category', [
      'category1Id',
      'category2Id',
      'category3Id',
      'category1List',
      'category2List',
      'category3List'
    ])
  },
  methods: {
    ...mapActions('category', [
      'getCategory1List',
      'getCategory2List',
      'getCategory3List'
    ]),
    ...mapMutations('category', ['SET_CATEGORY_3ID'])
  }
}
</script>

<style lang="sass" scoped></style>
